package hashMap;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/23-下午2:19
 * Since  :   1.0
 * Version:   1.0
 */
public class EmpLink {
    Emp head = new Emp(0, "", "");

    public void add(Emp emp) {
        Emp temp = head;
        while (true) {
            if (temp.next == null) {
                break;
            }

            temp = temp.next;
        }
        temp.next = emp;

    }

    public Emp findByID(int id) {
        if (head.next == null) {
            System.out.println("empty link");
        }

        Boolean flag = false;
        Emp temp = head;
        while (true) {
            if (temp.id == id) {
                flag = true;
                break;
            }
            temp = temp.next;
        }
        if (flag) {
            return temp;
        } else {
            System.out.println("no such element");
            return null;
        }


    }

    public void show() {
        if (head.next == null) {
            System.out.println("empty link");
        }
        Emp temp = head;
        while (true) {
            System.out.println(temp);
            if (temp.next == null) {
                break;
            }
            temp = temp.next;

        }


    }

    public void delByID(int id){
        if (head.next == null) {
            System.out.println("empty link");
        }
        Boolean flag=false;
        Emp temp=head;

        while (true){
            if(temp.next.id==id){
                flag =true;
                break;
            }
            temp=temp.next;
        }

        if (flag) {
            temp.next=temp.next.next;
            System.out.println("success delete the node");
        }else {
            System.out.println("the link no such node");
        }

    }


}
